package edu.umuc.cmsc495_final_project;

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.JEditorPane;


public class hostessGUI extends JFrame implements allGUI {

	JTree patronWaitTree;

	JEditorPane tablePane;
	JScrollPane tableScrollPane;
	JPanel detailPane;
	JButton newReservation;
	JButton newWalkin;
	JLabel lblDetail;
	JScrollPane patronWaitTreeView;
	JButton newSeat;
	JButton cancelSeat;
	JSplitPane splitPane;
	
	newDiner diner;

	DefaultMutableTreeNode top;
	DefaultMutableTreeNode time;
	DefaultMutableTreeNode reservation;
	DefaultMutableTreeNode walkin;
	DefaultMutableTreeNode bar;


	public hostessGUI() {
		super();
		
		System.out.println("opening hostess panel");
		
		//
		setName("Hostess");
		setBounds(0,panelStartY,panelWidth,panelEndHeight);
		setVisible(true);
		setLayout(new BorderLayout());
		removeNotify();  
		setUndecorated(true);  
		addNotify();  
		
		// show main body
		mainBody();
	}

	public void mainBody() {

		Font font = new Font("Verdana", Font.BOLD, 40);

		// table display area
		tablePane = new JEditorPane();
		tablePane.setEditable(false);

		// Put the table display pane in a scroll pane incase items are too big
		tableScrollPane = new JScrollPane(tablePane);

		// reservation area
		detailPane = new JPanel(new GridBagLayout());
		// setup for layout

		newReservation = new JButton("New Reservation");
		
		GridBagConstraints c = new GridBagConstraints();
		c.fill = GridBagConstraints.HORIZONTAL;
		c.ipady = 80;
		c.weightx = 1;
		c.gridy = 1;
		detailPane.add(newReservation, c);

		/*
		newWalkin = new JButton("New Walk-in");
		
		c.fill = GridBagConstraints.HORIZONTAL;
		c.ipady = 80;
		c.weightx = 1;
		c.gridy = 2;
		detailPane.add(newWalkin, c);
		*/

		lblDetail = new JLabel("Details", JLabel.CENTER);
		lblDetail.setFont(font);
		c.fill = GridBagConstraints.HORIZONTAL;
		c.ipady = 0;
		c.weightx = 1;
		c.gridy = 3;
		detailPane.add(lblDetail, c);

		// Patron wait Tree
		top = new DefaultMutableTreeNode("Awaiting Patrons");
		createNodes(top);
		patronWaitTree = new JTree(top);

		GridBagConstraints d = new GridBagConstraints();
		// scrollpane for reservation area
		patronWaitTreeView = new JScrollPane(patronWaitTree);
		d.fill = GridBagConstraints.BOTH;
		d.weightx = 1;
		d.weighty = 1;
		d.gridy = 4;
		detailPane.add(patronWaitTreeView, d);

		newSeat = new JButton("Seat Guest");
		c.fill = GridBagConstraints.HORIZONTAL;
		c.ipady = 80;
		c.weightx = 1;
		c.gridy = 5;
		c.insets = new Insets(5, 5, 5, 5); // top padding
		detailPane.add(newSeat, c);

		cancelSeat = new JButton("Cancel Guest");
		c.fill = GridBagConstraints.HORIZONTAL;
		c.ipady = 80;
		c.weightx = 1;
		c.gridy = 6;
		c.insets = new Insets(5, 5, 5, 5); // top padding
		detailPane.add(cancelSeat, c);

		// full split pane window
		splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,tableScrollPane, detailPane);// table display left, reservation
												// window right
		splitPane.setOneTouchExpandable(true);
		splitPane.setDividerLocation((int)(panelWidth*.80));

		// add to hostess frame
		add(splitPane);
	}

	// TODO this WILL need to be moved to module.java once completed ... because of the calls to db
	protected void createNodes(DefaultMutableTreeNode top) {

		reservation = new DefaultMutableTreeNode(DineType.RESERVATION);
		walkin = new DefaultMutableTreeNode(DineType.WALKIN);
		bar = new DefaultMutableTreeNode(DineType.BAR);
		
		// add dine types
		top.add(reservation); 
		top.add(walkin); 
		top.add(bar);
		
		/*
		// adds nodes
		for (int i = 0; i < db.patrons.size(); i++) {
			
			if (!db.patrons.get(i).isSeated()) {
				switch (db.patrons.get(i).getDineType()) {
				case RESERVATION: {
					reservation.add(new DefaultMutableTreeNode(db.patrons
							.get(i)));
					break;
				}
				case WALKIN: {
					walkin.add(new DefaultMutableTreeNode(db.patrons.get(i)));
					break;
				}
				case BAR: {
					bar.add(new DefaultMutableTreeNode(db.patrons.get(i)));
					break;
				}
				}
			}
		}
		*/
	}
}